<template>
  <div>
    <common-head title="所有联系人"/>
    <div class="wrap">
      <!-- <div class="box" v-if="!list.length">
        列表为空
      </div> -->
      <van-address-list
        v-model="chosenAddressId"
        :list="$store.state.contact.contacts"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="select"
      />
    </div>
  </div>
</template>

<script>
import CommonHead from '../../components/CommonHead.vue'
export default {
  data () {
    return {
      chosenAddressId: -1
    }
  },
  created () {
    this.initChoseId()
  },
  methods: {
    select (contact) {
      // console.log(contact, 111)
      this.$store.commit('order/change_contact', contact)
      this.$router.replace('/currentOrder')
    },
    onAdd () {
      this.$router.push('/contactAdd')
    },
    onEdit (contact, i) {
      // console.log(contact, i)
      this.$router.push({
        path: '/contactEdit',
        query: {
          id: i
        }
      })
    },
    initChoseId () {
      const contacts = this.$store.state.contact.contacts
      const defualtContact = contacts.find(contact => contact.isDefault)
      this.chosenAddressId = defualtContact.id
    }
  },
  components: {
    CommonHead
  }
}
</script>

<style lang="scss" scoped>
.wrap{
  margin-top: 46px;
}
</style>
